package com.atguigu.lease.app.controller;

import com.atguigu.lease.app.service.ViewAppointmentService;
import com.atguigu.lease.common.handler.StgyAppAuthInterceptor;
import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.bean.ViewAppointment;
import com.atguigu.lease.model.vo.app.AppointmentDetailVo;
import com.atguigu.lease.model.vo.app.AppointmentItemVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "预约模块")
@RestController
@RequestMapping("/app/appointment")
public class ViewAppointmentController {
    @Autowired
    ViewAppointmentService viewAppointmentService;

    @Operation(summary = "1、新增或更新预约")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody ViewAppointment viewAppointment) {
        //给预约绑定用户
        viewAppointment.setUserId(StgyAppAuthInterceptor.APP_USER_THREAD_LOCAL.get().getId());
        viewAppointmentService.saveOrUpdate(viewAppointment);
        return Result.ok();
    }

    @Operation(summary = "2、查询用户的预约列表")
    @GetMapping("listItem")
    public Result<List<AppointmentItemVo>> listItem() {
        List<AppointmentItemVo> appointmentItemVos = viewAppointmentService.listItem();
        return Result.ok(appointmentItemVos);
    }

    @Operation(summary = "3、查询用户的预约详情")
    @GetMapping("getDetailById")
    public Result<AppointmentDetailVo> getDetailById(@RequestParam Long id) {
        return Result.ok(viewAppointmentService.getDetailById(id));
    }
}